//
//  ViewController.m
//  BigImageShow
//
//  Created by liuyan on 16/8/10.
//  Copyright © 2016年 liuyan. All rights reserved.
//

#import "ViewController.h"
#import "BigImageCollectionView.h"
#import "BigImageIndexCollectionView.h"
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenheight [UIScreen mainScreen].bounds.size.height

@interface ViewController ()
@property (nonatomic, strong)BigImageCollectionView *bigImgCollView;
@property (nonatomic, strong)BigImageIndexCollectionView *indexCollView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self uiconfig];
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)uiconfig{
    _bigImgCollView = [[BigImageCollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenheight - 70)];
    _bigImgCollView.itemWidth = kScreenWidth;
    _bigImgCollView.minLineSpacing = 0;
    _bigImgCollView.movieModelArray = @[@"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1470812555&di=0403008e8035965aae391e8aab2622db&src=http://d.hiphotos.baidu.com/image/pic/item/0ff41bd5ad6eddc492d491153ddbb6fd52663328.jpg", @"http://img.tupianzj.com/uploads/allimg/160809/9-160P9225136.jpg", @"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1470812555&di=aa2a3126db931f9cb960475cfaa4fcaf&src=http://e.hiphotos.baidu.com/image/pic/item/14ce36d3d539b600be63e95eed50352ac75cb7ae.jpg", @"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1470812886&di=88cf9cd68db0cea47f888766691edafa&src=http://c.hiphotos.baidu.com/image/pic/item/2fdda3cc7cd98d10533d1de3253fb80e7aec9072.jpg", @"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1470812555&di=4600fd83ccadfb9c68cd41b68dc1b076&src=http://h.hiphotos.baidu.com/image/pic/item/43a7d933c895d143b233160576f082025aaf074a.jpg", @"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1470907473&di=7db76377055d28378580017fdd6d32ca&src=http://h.hiphotos.baidu.com/image/pic/item/f9dcd100baa1cd11dd1855cebd12c8fcc2ce2db5.jpg", @"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1470907473&di=f976cc8b76b58298bf05d4ebbea0e0c2&src=http://d.hiphotos.baidu.com/image/pic/item/562c11dfa9ec8a13f075f10cf303918fa1ecc0eb.jpg", @"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1470907473&di=73ef06f6a34435481c5c2976d982ca77&src=http://a.hiphotos.baidu.com/image/pic/item/f9dcd100baa1cd11daf25f19bc12c8fcc3ce2d46.jpg",@"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1470812555&di=0403008e8035965aae391e8aab2622db&src=http://d.hiphotos.baidu.com/image/pic/item/0ff41bd5ad6eddc492d491153ddbb6fd52663328.jpg", @"http://img.tupianzj.com/uploads/allimg/160809/9-160P9225136.jpg", @"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1470812555&di=aa2a3126db931f9cb960475cfaa4fcaf&src=http://e.hiphotos.baidu.com/image/pic/item/14ce36d3d539b600be63e95eed50352ac75cb7ae.jpg", @"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1470812886&di=88cf9cd68db0cea47f888766691edafa&src=http://c.hiphotos.baidu.com/image/pic/item/2fdda3cc7cd98d10533d1de3253fb80e7aec9072.jpg", @"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1470812555&di=4600fd83ccadfb9c68cd41b68dc1b076&src=http://h.hiphotos.baidu.com/image/pic/item/43a7d933c895d143b233160576f082025aaf074a.jpg", @"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1470907473&di=7db76377055d28378580017fdd6d32ca&src=http://h.hiphotos.baidu.com/image/pic/item/f9dcd100baa1cd11dd1855cebd12c8fcc2ce2db5.jpg", @"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1470907473&di=f976cc8b76b58298bf05d4ebbea0e0c2&src=http://d.hiphotos.baidu.com/image/pic/item/562c11dfa9ec8a13f075f10cf303918fa1ecc0eb.jpg", @"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1470907473&di=73ef06f6a34435481c5c2976d982ca77&src=http://a.hiphotos.baidu.com/image/pic/item/f9dcd100baa1cd11daf25f19bc12c8fcc3ce2d46.jpg"];
    [self.view addSubview:_bigImgCollView];
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenheight - 70, kScreenWidth, 70)];
    bottomView.backgroundColor = [UIColor whiteColor];
    _indexCollView = [[BigImageIndexCollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 42)];
    _indexCollView.itemWidth = 21;
    _indexCollView.minLineSpacing = 1;
    _indexCollView.movieModelArray = _bigImgCollView.movieModelArray;
    [bottomView addSubview:_indexCollView];
    [self.view addSubview:bottomView];
    [_indexCollView collectionViewDidScrollWithScrollBlock:^(NSIndexPath *indexPath) {
        [_bigImgCollView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
    }];
    [_bigImgCollView collectionViewDidScrollWithScrollBlock:^(UICollectionView *scrollView) {
        //这里的百分比是大cell的width/小的cell的width加上间隙
        float rate = 34/kScreenWidth;
        CGPoint offset = scrollView.contentOffset;
        CGFloat x = offset.x * rate;
        //按照比例设置indexCollView的偏移量
        offset.y = _indexCollView.contentOffset.y;
        offset.x = x;
        [_indexCollView setContentOffset:offset animated:YES];
    }];

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
